/*******************************************************************************
* Project: QSAR(Cute Software Architecture) 
*
* Copyright: Copyright(C) 2024 by YuetingBen, All Rights Reserved
*
* File name: AppDiag.c
*
* Brief: ;
*
* Author: Yueting.Ben
*
* Module: AppDiag
*
* Revision:
* --------------------------------------------------------------------------------
* v0.1: 
* Generation Time: 2025-01-07 18:25:30
*
**********************************************************************************/

/** HEADER FILES **/
#include "AppDiag.h"


/** MACRO DEFINITION **/


/** TYPEDEF DEFINITION **/


/** LOCAL DATA DECLARATION **/


/** GLOBAL DATA DECLARATION **/


/** LOCAL FUNCTION DECLARATION **/


/** GLOBAL FUNCTION DECLARATION **/
Std_ReturnType AppDiag_Security_Level1_GetSeed(
    Dcm_OpStatusType OpStatus,
    uint8* Seed,
    Dcm_NegativeResponseCodeType* ErrorCode
);

Std_ReturnType AppDiag_Security_Level1_CompareKey(
    const uint8* Key,
    Dcm_OpStatusType OpStatus,
    Dcm_NegativeResponseCodeType* ErrorCode
);

Std_ReturnType AppDiag_DID_0xF195_SystemSupplierECUSoftwareVersionNumberDataIdentifier_ReadData(
    uint8* Data
);

Std_ReturnType AppDiag_DID_0xF190_VINDataIdentifier_ReadData(
    uint8* Data
);

Std_ReturnType AppDiag_DID_0xF190_VINDataIdentifier_WriteData(
    uint8* Data
);

Std_ReturnType AppDiag_DID_0x1200_Voltage_ReadData(
    uint8* Data
);

Std_ReturnType AppDiag_DID_0x0200_IO_Testing_ReadData(
    uint8* Data
);


/** LOCAL DATA **/
static uint8 AppDiag_TestingDid[70] = {0x00};
static uint8 Vin[17] = {0x00};
static uint8 QsarSoftwareVersionNumber[8u] = "00.00.04";
static uint8 IoTestingDataValue = 0x00;


/** GLOBAL DATA **/


/** LOCAL FUNCTION **/


/** GLOBAL FUNCTION **/
Std_ReturnType AppDiag_Security_Level1_GetSeed(
    Dcm_OpStatusType OpStatus,
    uint8* Seed,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
    Std_ReturnType retVal = E_OK;
    
    Seed[0] = 0xA1;
    Seed[1] = 0xA2;
    Seed[2] = 0xA3;
    Seed[3] = 0xA4;
    
    return(retVal);
}


Std_ReturnType AppDiag_Security_Level1_CompareKey(
    const uint8* Key,
    Dcm_OpStatusType OpStatus,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
    Std_ReturnType retVal = E_NOT_OK;
    
    if(0xAA == Key[0])
    {
        retVal = E_OK;
    }
    
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0xF195_SystemSupplierECUSoftwareVersionNumberDataIdentifier_ReadData
* -Brief        Did read Data
* -Details      None
* -Param[in]    Data: Input data
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0xF195_SystemSupplierECUSoftwareVersionNumberDataIdentifier_ReadData(
    uint8* Data
)
{
    Std_ReturnType retVal = E_OK;
    uint8 i;

    for(i = 0; i < 8u; i++)
    {
        Data[i] = QsarSoftwareVersionNumber[i];
    }
   
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0xF190_VINDataIdentifier_ReadData
* -Brief        Did read Data
* -Details      None
* -Param[in]    Data: Input data
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0xF190_VINDataIdentifier_ReadData(
    uint8* Data
)
{
    Std_ReturnType retVal = DCM_E_PENDING;
    static uint8 readFlag = RESET;
    uint8 i;

    if(RESET == readFlag)
    {
        NvM_ReadBlock(NvmConf_Block_DidVin, (uint8*)Vin);
        readFlag = SET;
    }
    else
    {
        NvM_GetErrorStatus(NvmConf_Block_DidVin, (NvM_RequestResultType*)&retVal);

        if(E_OK == retVal)
        {
            for(i = 0; i < 17; i++)
            {
                Data[i] = Vin[i];
            }
        }
    }

    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0xF190_VINDataIdentifier_WriteData
* -Brief        Did write Data
* -Details      None
* -Param[out]   Data: Output data
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0xF190_VINDataIdentifier_WriteData(
    uint8* Data
)
{
     Std_ReturnType retVal = E_OK;
     uint8 i;
     
     for(i = 0; i < 17; i++)
     {
         Vin[i] = Data[i];
     }
    
     NvM_WriteBlock(NvmConf_Block_DidVin, Vin);
     
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0x1200_Voltage_ReadData
* -Brief        Did read Data
* -Details      None
* -Param[in]    Data: Input data
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0x1200_Voltage_ReadData(
    uint8* Data
)
{
    Std_ReturnType retVal = E_OK;
   
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0x0200_IO_Testing_ReadData
* -Brief        Did read Data
* -Details      None
* -Param[in]    Data: Input data
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0x0200_IO_Testing_ReadData(
    uint8* Data
)
{
    Std_ReturnType retVal = E_OK;

    *Data = IoTestingDataValue;
   
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0x0200_IO_Testing_ReturnControlToECU
* -Brief        Did IO control
* -Details      None
* -Param[in]    controlMask: Control Mask
* -Param[out]   ErrorCode: NRC
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0x0200_IO_Testing_ReturnControlToECU(
    uint8* controlMask,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
    Std_ReturnType retVal = E_OK;

    IoTestingDataValue = *controlMask + 0x10;
   
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0x0200_IO_Testing_ResetToDefault
* -Brief        Did IO control
* -Details      None
* -Param[in]    controlMask: Control Mask
* -Param[out]   ErrorCode: NRC
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0x0200_IO_Testing_ResetToDefault(
    uint8* controlMask,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
    Std_ReturnType retVal = E_OK;

    IoTestingDataValue = *controlMask + 0x20;
   
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0x0200_IO_Testing_FreezeCurrentState
* -Brief        Did IO control
* -Details      None
* -Param[in]    controlMask: Control Mask
* -Param[out]   ErrorCode: NRC
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0x0200_IO_Testing_FreezeCurrentState(
    uint8* controlMask,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
    Std_ReturnType retVal = E_OK;

    IoTestingDataValue = *controlMask + 0x30;
   
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_DID_0x0200_IO_Testing_ShortTermAdjustment
* -Brief        Did IO control
* -Details      None
* -Param[in]    controlMask: Control Mask
* -Param[out]   ErrorCode: NRC
* -Return       E_OK: Request was successful
*               E_NOT_OK: Request was not successful          
*******************************************************************************/
Std_ReturnType AppDiag_DID_0x0200_IO_Testing_ShortTermAdjustment(
    const uint8* ControlStateInfo,
    uint8* controlMask,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
    Std_ReturnType retVal = E_OK;

    IoTestingDataValue = *controlMask + 0x40;
   
    return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_RoutingId_0x0101_TestingRoutingIdA_StartRequestControl
* -Brief        RoutingId_0101_TestingRoutingId StartRoutine
* -Details      None
* -Param[in]    DataIn: routineControlOptionRecord
* -Param[in]    DataOut: routineStatusRecord
* -Return       E_OK:Requestwassuccessful
*               E_NOT_OK:Requestwasnotsuccessful          
*******************************************************************************/
Std_ReturnType AppDiag_RoutingId_0x0101_TestingRoutingIdA_StartRequestControl(
    Dcm_OpStatusType OpStatus,
    const uint8* dataInVar,
    uint8* dataOutVar,
    uint16* variableDataLength,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
   Std_ReturnType retVal = E_OK;
   
   return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_RoutingId_0x0101_TestingRoutingIdA_StopRequestControl
* -Brief        RoutingId_0101_TestingRoutingId StopRoutine
* -Details      None
* -Param[in]    DataIn: routineControlOptionRecord
* -Param[in]    DataOut: routineStatusRecord
* -Return       E_OK:Requestwassuccessful
*               E_NOT_OK:Requestwasnotsuccessful          
*******************************************************************************/
Std_ReturnType AppDiag_RoutingId_0x0101_TestingRoutingIdA_StopRequestControl(
    Dcm_OpStatusType OpStatus,
    const uint8* dataInVar,
    uint8* dataOutVar,
    uint16* variableDataLength,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
   Std_ReturnType retVal = E_OK;
   
   return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_RoutingId_0x0101_TestingRoutingIdA_RequestResults
* -Brief        RoutingId_0101_TestingRoutingId RequestResults
* -Details      None
* -Param[in]    DataIn: routineControlOptionRecord
* -Param[in]    DataOut: routineStatusRecord
* -Return       E_OK:Requestwassuccessful
*               E_NOT_OK:Requestwasnotsuccessful          
*******************************************************************************/
Std_ReturnType AppDiag_RoutingId_0x0101_TestingRoutingIdA_RequestResults(
    Dcm_OpStatusType OpStatus,
    const uint8* dataInVar,
    uint8* dataOutVar,
    uint16* variableDataLength,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
   Std_ReturnType retVal = E_OK;
   
   return(retVal);
}


/*******************************************************************************
* -Name         AppDiag_RoutingId_0x0102_TestingRoutingIdB_StartRequestControl
* -Brief        RoutingId_0101_TestingRoutingId StartRoutine
* -Details      None
* -Param[in]    DataIn: routineControlOptionRecord
* -Param[in]    DataOut: routineStatusRecord
* -Return       E_OK:Requestwassuccessful
*               E_NOT_OK:Requestwasnotsuccessful          
*******************************************************************************/
Std_ReturnType AppDiag_RoutingId_0x0102_TestingRoutingIdB_StartRequestControl(
    Dcm_OpStatusType OpStatus,
    const uint8* dataInVar,
    uint8* dataOutVar,
    uint16* variableDataLength,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
   Std_ReturnType retVal = E_OK;
   
   return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_RoutingId_0x0102_TestingRoutingIdB_StopRequestControl
* -Brief        RoutingId_0101_TestingRoutingId StopRoutine
* -Details      None
* -Param[in]    DataIn: routineControlOptionRecord
* -Param[in]    DataOut: routineStatusRecord
* -Return       E_OK:Requestwassuccessful
*               E_NOT_OK:Requestwasnotsuccessful          
*******************************************************************************/
Std_ReturnType AppDiag_RoutingId_0x0102_TestingRoutingIdB_StopRequestControl(
    Dcm_OpStatusType OpStatus,
    const uint8* dataInVar,
    uint8* dataOutVar,
    uint16* variableDataLength,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
   Std_ReturnType retVal = E_OK;
   
   return(retVal);
}

/*******************************************************************************
* -Name         AppDiag_RoutingId_0x0102_TestingRoutingIdB_RequestResults
* -Brief        RoutingId_0101_TestingRoutingId RequestResults
* -Details      None
* -Param[in]    DataIn: routineControlOptionRecord
* -Param[in]    DataOut: routineStatusRecord
* -Return       E_OK:Requestwassuccessful
*               E_NOT_OK:Requestwasnotsuccessful          
*******************************************************************************/
Std_ReturnType AppDiag_RoutingId_0x0102_TestingRoutingIdB_RequestResults(
    Dcm_OpStatusType OpStatus,
    const uint8* dataInVar,
    uint8* dataOutVar,
    uint16* variableDataLength,
    Dcm_NegativeResponseCodeType* ErrorCode
)
{
   Std_ReturnType retVal = E_OK;
   
   return(retVal);
}


/*******************************************************************************
* -Name         AppDiag_Init
* -Brief        This function initializes the AppDiag module
* -Details      None
* -Param[in]    CfgPtr: Pointer to the CanTp post-build configuration data
* -Return       None          
*******************************************************************************/
void AppDiag_Init(
    const AppDiag_ConfigType* CfgPtr
)
{
    AppDiag_TestingDid[57] = 0x57;
    AppDiag_TestingDid[58] = 0x58;
    AppDiag_TestingDid[59] = 0x59;
    AppDiag_TestingDid[60] = 0x60;
    AppDiag_TestingDid[61] = 0x61;
    AppDiag_TestingDid[62] = 0x62;
    AppDiag_TestingDid[63] = 0x63;
    AppDiag_TestingDid[64] = 0x64;
}



